module AjaxPageHelper

  # Ocultar el inline form que está siendo editado y actualizar la tabla.
  def hide_inline(inline_form, flash_text, element)
    page[inline_form].visual_effect :blind_up, :duration => 0.2
    page.replace_html :flash_area, flash_text
    page.delay(0.2) do 
      model = element.class.to_s.underscore
      page["#{model}_grid"].replace_html :partial => "list"
      page << "if ($('#{element.id_}')) {"
        page[element.id_].visual_effect :highlight, :duration => 1
      page << "};"
      page["#{model}_new_link"].show
    end
  end
  
  def update_inline(inline_form, locals)
    page[inline_form].replace_html :partial => '../../vendor/plugins/acts_as_dynamic/files/app/views/varias/inline_form',
      :locals => locals
  end
  
  # Actualizar el formulario inline, efecto para mostrarlo y activar/desctivar botones.
  def inline_blind_down(model, locals)
    inline_form = "#{model}_inline_form"
    page.update_inline(inline_form, locals)
    page.visual_effect :blind_down, inline_form, :duration => 0.2
    page["#{model}_new_link"].hide
    page["#{model}_cancel_link"].show
  end
  
end

ActionView::Base.send :include, AjaxPageHelper
